home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / BBS / MUBBS / Tfiles10.cpt / textfiles Code / textfiles.c < prev    next >
Text File  |  1992-01-21  |  5KB  |  187 lines

  1. /*
  2.  *   Textfiles Module - Version 1.0 - By Scott Szretter
  3.  *
  4.  *      (C)1991 Scott Szretter - Please see the file "COPYRITE.SPS"
  5.  *
  6.  *        ))) Version Changes (((
  7.  * --Version-------------Notes-----------------------------------------------------------------
  8.  *  1.0 ->  1.0 ... Name change (gfiles -> textfiles) & ease of use for user upgrade. 
  9.  *
  10.  *  This program may not be sold for profit!
  11.  *  The source code is being release for educational purposes only.
  12.  *  I take no responsibility for any damage resulting from this code.
  13.  */
  14. #define INMAIN
  15. #include     <SetUpA4.h>
  16. #include    "MUBBS Module.h"
  17. pascal void main (mode1,G1,P1)
  18.        short mode1;
  19.        struct GS *G1;
  20.        Ptr *P1;{
  21. Handle temph;
  22. float version = 0.5; /* version of MUBBS */
  23. RememberA0(); SetUpA4(); 
  24. asm { _RecoverHandle }; asm {move.l a0,temph}; HLock(temph); /* lock our module. */
  25. G=G1; 
  26. mode[u]=mode1;
  27.  
  28. switch (mode[u]) {
  29.     case 2:
  30.         Textfiles();
  31.         G->moduleresult=0;
  32.         break;
  33.     case 98:
  34.         versionck(version);
  35.         break;        
  36.     case 0:
  37.         strcpy (G->programmer,"Scott Szretter");
  38.         G->moduleresult=0;
  39.         break;
  40.     default:
  41.         G->moduleresult=1;
  42.         break;};
  43. HUnlock(temph); /* unlock module.*/
  44. RestoreA4();}
  45.  
  46. /****        *   *    *    -Textfiles-   *   *   *   *          ****/
  47. Textfiles()  {
  48. FILE *stream; 
  49. char tempstring[100];
  50. char m_realnames[12][41];
  51. char modulesc[12][10];
  52. short i,a,f;
  53. short itemp;
  54.  
  55. if (!G->online[u]) return;
  56. loguser(G->modulename[u]); 
  57. print("C> Line %d %s, at: %s\n",(u+1),G->username[u],G->modulename[u]);
  58.  
  59. strcpy(tempstring,":textfiles:");
  60. strcat(tempstring,G->modulename[u]);
  61. strcat(tempstring,".intro");
  62. sendtext(tempstring);
  63.  
  64.  
  65. strcpy(tempstring,":textfiles:");
  66. strcat(tempstring,G->modulename[u]);
  67. strcat(tempstring,".info");
  68.  
  69. i = 0;
  70. /* Open the file */
  71. if ((stream = fopen(tempstring, "r")) == NULL) {    
  72.     send("]FILE ERROR cannot open %s ", /*its a %d ,errno,*/  tempstring);
  73.     print("]FILE ERROR!!!! cannot open %s ",tempstring);
  74.     return;
  75.     }
  76. else    /* If no error, read from the file */
  77.     {                
  78.     a = 0;
  79.     while (a == 0){
  80.             if(fgets(modulesc[i],5,stream) != NULL) {  /* Read and check for EOF */
  81.                 if (fgets(m_realnames[i],39,stream) != NULL)  {  /* Read and check for EOF */
  82.                     remlf(m_realnames[i]); /* take out line feed */
  83.                     remlf(modulesc[i]);
  84.                     i++;
  85.                     if (i >= 9) a = 1;        
  86.                 }
  87.             }
  88.             else {
  89.                 a = 1;
  90.                 }
  91.         }
  92.     fclose(stream);
  93.     if (!G->online[u]) return;
  94.     }
  95.  
  96.  /* Display list of text files - first coming into module */
  97.  
  98. f = 0;
  99. a = 0;
  100. while (a == 0){
  101.     itemp=strtoint(modulesc[f]);
  102.     if(G->userpriv[u] >= itemp){ 
  103.         send("]");
  104.         send("(");
  105.         inttostr(f,tempstring);
  106.         send(tempstring);
  107.         send(") ");
  108.         send(m_realnames[f]);} /* userpriv >= itemp */
  109.     f++;
  110.     if (f >= i) a = 1;        
  111.             } /* while a==0 */
  112. f=0;
  113. Mainpart:
  114.         if (!G->online[u]) return;
  115.         if (!(cmd1("]]Type File Number To Display   -Or-  ]  >> Help, Files, Quit:"))) G->online[u]=FALSE;
  116.         send(G->CR[u]);
  117.             if (G->input[u] =='Q') {  /* user quits */
  118.                 print("C> Exiting Textfiles -> ",G->username[u]);
  119.                 return;} /* input = Q */
  120.             if (G->input[u] =='H') {  /* user wants help */
  121.                 strcpy(tempstring,":textfiles:");
  122.                 strcat(tempstring,G->modulename[u]);
  123.                 strcat(tempstring,".help");
  124.                 send (G->CR[u]);
  125.                 sendtext(tempstring);
  126.                 send ("]]Textfiles Module 1.0 By - Scott Szretter");
  127.                 goto Mainpart;
  128.                 } /* input = H */
  129.             if (G->input[u] =='F'){  /* user wants list of files */
  130.                 f = 0;
  131.                 a = 0;
  132.                 while (a == 0){
  133.                     itemp=strtoint(modulesc[f]);
  134.                     if(G->userpriv[u] >= itemp){ 
  135.                         send("]");
  136.                         send("(");
  137.                         inttostr(f,tempstring);
  138.                         send(tempstring);
  139.                         send(") ");
  140.                         send(m_realnames[f]);}
  141.                     f++;
  142.                     if (f >= i) a = 1;        
  143.                                } /* while a==0 */
  144.                     f=0;
  145.                     goto Mainpart;
  146.                                }  /* input = F */
  147.             if (G->input[u] =='Z'){ 
  148.  
  149.                   send(modulesc[f]);
  150.                  send("]");
  151.                  send(m_realnames[f]);
  152.                 goto Mainpart;
  153.  
  154.              } /* end Z */
  155.              strcpy(tempstring,&G->input[u]);
  156.              f=strtoint(tempstring);
  157.             if (f > i-1) {
  158.                 send("]Invalid selection (#,H,Q,or F) please...]");
  159.                 goto Mainpart;}
  160.             if (f < 0) {
  161.                 send("]Invalid selection (#,H,Q,or F) please...]");
  162.                 goto Mainpart;}
  163.             send("]]");
  164.             strcpy(tempstring,":textfiles:");
  165.             itemp=strtoint(modulesc[f]);
  166.             if(G->userpriv[u] >= itemp) {
  167.                 strcat(tempstring,m_realnames[f]);
  168.                 sendtext(tempstring); }
  169.             else 
  170.                 send("]]Sorry, you do not have access to that file...");
  171.                 
  172.             goto Mainpart;
  173. }   /* Textfiles() */
  174.  
  175. remlf(string)
  176. char *string;
  177. {
  178. short temp,b;
  179. b = strlen(string);
  180. for (temp=0; temp<= b; temp++) 
  181.     {
  182.     if (string[temp] == 10)
  183.         string[temp] = 0;
  184.     }
  185.  
  186. }
  187.